import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
  RouterOptions,
  Router,
  RouterHistory
} from "vue-router";
import { getRoutesDataList } from "./routes";
// const apiUrl = import.meta.env.VITE_API_URL;

class RouterUtils {
  routes: Array<RouteRecordRaw>;

  constructor(routes: Array<RouteRecordRaw>) {
    this.routes = routes;
  }

  // 使用 import.meta.env
  startCreateRouter(history: RouterHistory = createWebHistory()): Router {
    const options: RouterOptions = {
      history,
      routes: this.routes
    };
    return createRouter(options);
  }
}

export default new RouterUtils(getRoutesDataList()).startCreateRouter();
